package suse.hotel.admin.admin.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import suse.hotel.admin.admin.DTO.OrderDTO;
import suse.hotel.admin.admin.Mapper.OrderMapper;
import suse.hotel.admin.admin.Provider.JsonProvider;

import java.util.List;

@Service
public class OrderService {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    JsonProvider jsonProvider;
    public String selOrders(int page,int limit){
        PageHelper.startPage(page,limit);
        List<OrderDTO> userDTOS = orderMapper.listOrders();
        PageInfo<OrderDTO> pageInfo=new PageInfo<>(userDTOS);
        return jsonProvider.toJson(pageInfo);
    }
    public String selOrdersById(int page,int limit,String key){
        PageHelper.startPage(page,limit);
        List<OrderDTO> userDTOS = orderMapper.searchOrder(key);
        PageInfo<OrderDTO> pageInfo=new PageInfo<>(userDTOS);
        return jsonProvider.toJson(pageInfo);
    }
}
